//
//  HZProductCommentsVCData.m
//  app
//
//  Created by 刘华舟 on 15/6/3.
//  Copyright (c) 2015年 hdaren. All rights reserved.
//

#import "HZProductCommentsVCData.h"
#import "NSDictionary+SafetyGet.h"

static const NSInteger kPageSize = 15;

@implementation HZProductCommentsVCData

+ (instancetype)dataWithDictionary:(NSDictionary *)dict{
    return [[HZProductCommentsVCData alloc] initDataWithDictionary:dict];
}
- (instancetype)initDataWithDictionary:(NSDictionary *)dict{
    if (self = [super init]) {
        if ([dict count]) {
            NSMutableArray *dataArray = [NSMutableArray array];
 
            for (NSDictionary *cell in [dict arrayForKey:APIKEY_mall_comments]) {
                HZGoodsCommentModel *model = [HZGoodsCommentModel modelWithDictionary:cell];
                [dataArray addObject:model];
            }
            
            self.commentsArray = dataArray;
            if (self.commentsArray.count < kPageSize) {
                self.noMoreData = YES;
            }else{
                self.noMoreData = NO;
            }
            
            self.lastObjectIndex = self.commentsArray.count - 1;
        }else{
            self.commentsArray = [NSMutableArray array];
            self.noMoreData = YES;
            self.lastObjectIndex = 0;
        }

    }
    return self;
}

-(HZGoodsCommentModel *)fetchCellModelAtRow:(NSInteger)row{
    return [self.commentsArray objectAtIndex:row];
}

- (BOOL)addMoreDataWithArray:(NSArray *)moreDatas{
    if (moreDatas.count <= 0) {
        self.noMoreData = YES;
        return NO;
    }else{
        if (moreDatas.count < kPageSize) {
            self.noMoreData = YES;
        }
        
        NSMutableArray *totalArray = [NSMutableArray arrayWithArray:self.commentsArray];
        for (NSDictionary *dict in moreDatas) {
            HZGoodsCommentModel *model = [HZGoodsCommentModel modelWithDictionary:dict];
            [totalArray addObject:model];
        };
        self.commentsArray = totalArray;
        
        self.lastObjectIndex = self.commentsArray.count - 1;
    }
    return YES;
}

@end
